{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ISAT.scripts.coco import COCO\n",
    "from ISAT.scripts.yolo import YOLO\n",
    "from ISAT.scripts.labelme import LABELME\n",
    "from ISAT.scripts.voc import VOC\n",
    "from ISAT.scripts.voc_detection import VOCDetect"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. COCO"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## COCO  to ISAT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading annotations into memory...\n",
      "Done (t=0.00s)\n",
      "creating index...\n",
      "index created!\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Load COCO with image id 76261: 100%|█████████████| 5/5 [00:00<00:00, 939.33it/s]\n",
      "Save ISAT to 000000076261.json: 100%|████████████| 5/5 [00:00<00:00, 554.85it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "coco = COCO()\n",
    "coco.read_from_coco(annotation_file='coco_tiny/coco_tiny.json')\n",
    "coco.save_to_ISAT(json_root='coco_tiny/coco2isat')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ISAT to COCO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Load ISAT from 000000100723.json: 100%|█████████| 5/5 [00:00<00:00, 1389.58it/s]\n",
      "Integrate 000000076261: 100%|███████████████████| 5/5 [00:00<00:00, 2273.09it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Save COCO json finished.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "coco.read_from_ISAT(json_root='coco_tiny/isat/')\n",
    "coco.save_to_coco(annotation_file='coco_tiny/isat2coco.json')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. YOLO"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## YOLO to ISAT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Load yolo txt 000000100723.txt: 100%|████████████| 5/5 [00:00<00:00, 224.09it/s]\n",
      "Save ISAT to 000000076261.json: 100%|████████████| 5/5 [00:00<00:00, 698.79it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yolo = YOLO()\n",
    "yolo.read_from_YOLO(img_root='coco_tiny/images/', txt_root='coco_tiny/yolo/')\n",
    "yolo.save_to_ISAT(json_root='coco_tiny/yolo2isat')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ISAT to YOLO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Load ISAT from 000000100723.json: 100%|█████████| 5/5 [00:00<00:00, 1174.48it/s]\n",
      "Save yolo to 000000076261.txt: 100%|█████████████| 5/5 [00:00<00:00, 506.50it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yolo.read_from_ISAT(json_root='coco_tiny/isat/')\n",
    "yolo.save_to_YOLO(txt_root='coco_tiny/isat2yolo')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. LABELME"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## LABELME to ISAT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Load labelme json 000000100723.json: 100%|██████| 5/5 [00:00<00:00, 1503.23it/s]\n",
      "Save ISAT to 000000076261.json: 100%|███████████| 5/5 [00:00<00:00, 1154.95it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labelme = LABELME()\n",
    "labelme.read_from_LABELME(json_root='coco_tiny/labelme/')\n",
    "labelme.save_to_ISAT(json_root='coco_tiny/labelme2isat')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ISAT to LABELME"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Load ISAT from 000000100723.json: 100%|█████████| 5/5 [00:00<00:00, 1227.12it/s]\n",
      "Save labelme to 000000076261.json: 100%|█████████| 5/5 [00:00<00:00, 419.29it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labelme.read_from_ISAT(json_root='coco_tiny/isat/')\n",
    "labelme.save_to_LABELME(json_root='coco_tiny/isat2labelme')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4. VOC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ISAT to VOC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Load ISAT from 000000100723.json: 100%|█████████| 5/5 [00:00<00:00, 1168.00it/s]\n",
      "Save to 000000076261.png: 100%|███████████████████| 5/5 [00:00<00:00, 25.38it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "voc = VOC()\n",
    "voc.read_from_ISAT(json_root='coco_tiny/isat/')\n",
    "voc.save_to_voc(png_root='coco_tiny/isat2voc')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5. VOC for object detection"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ISAT to XML ( voc for object detection)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Load ISAT from 000000100723.json: 100%|█████████| 5/5 [00:00<00:00, 1337.47it/s]\n",
      "Save xml to 000000076261.xml: 100%|█████████████| 5/5 [00:00<00:00, 1563.99it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "voc_ob = VOCDetect()\n",
    "voc_ob.read_from_ISAT(json_root='coco_tiny/isat')\n",
    "voc_ob.save_to_XML(xml_root='coco_tiny/isat2xml')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
